package action;

import server.whiteboard.WhiteBoardRequestThread;
import service.BoardService;
import utils.CommonUtils;

import java.util.List;

public class BoardAction {

    public void connect_board(WhiteBoardRequestThread.RequestContext rct) {
        long user_id = Long.valueOf(rct.param("user_id"));
        long board_id = Long.valueOf(rct.param("board_id"));
        BoardService.connectBoard(user_id, board_id, rct.getAddress(), rct);
    }

    public void update_board(WhiteBoardRequestThread.RequestContext rct) {
        List<String> updateShapeList = CommonUtils.convertJsonToList(rct.param("shape_list"), String.class);
        long board_id = Long.valueOf(rct.param("board_id"));
        BoardService.updateBoard(board_id, updateShapeList, rct);
    }

    public void save_board(WhiteBoardRequestThread.RequestContext rct) {
        long board_id = Long.valueOf(rct.param("board_id"));
        BoardService.saveBoard(board_id, rct);
    }

    public void clear_board(WhiteBoardRequestThread.RequestContext rct) {
        long board_id = Long.valueOf(rct.param("board_id"));
        BoardService.clearBoard(board_id, rct);
    }

    public void broadcast_msg(WhiteBoardRequestThread.RequestContext rct) {
        long board_id = Long.valueOf(rct.param("board_id"));
        String msg = rct.param("msg");
        long user_id = Long.valueOf(rct.param("account"));
        BoardService.broadcastMsg(board_id, msg, rct);
    }

    public void disconnect_board(WhiteBoardRequestThread.RequestContext rct) {
        long board_id = Long.valueOf(rct.param("board_id"));
        long user_id = Long.valueOf(rct.param("user_id"));
        BoardService.disconnectBoard(user_id, board_id, rct);
    }
}
